package com.droid.activitys;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.WindowManager;
import android.widget.ProgressBar;

import com.droid.R;

public class LoadingActivity extends Activity {
private ProgressBar progressBar;
    Handler mHandler = new Handler(){
        public void handleMessage(android.os.Message msg) {
            progressBar.setProgress(msg.what);
            if(msg.what==100){
                Intent it=new Intent(getApplicationContext(),MainActivity.class);//启动MainActivity
                startActivity(it);
                finish();//关闭当前活动
            }
        };
    };
    Runnable mRunnable = new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i <= 100; ) {
                Message msg = mHandler.obtainMessage();
                msg.what = i;
                i ++;
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                mHandler.sendMessage(msg);
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        setContentView(R.layout.activity_loading);
        progressBar = findViewById(R.id.progressBar);

        new Thread(mRunnable).start();
    }
}
